<?php
  $yhendus=new mysqli("localhost", "if13", "ifikad", "if13_alisiko1_k");
  if(isSet($_REQUEST["uusleht"])){
    $kask=$yhendus->prepare("INSERT INTO yritus (etteaste, aeg) VALUES (?, ?)");
    $kask->bind_param("ss", $_REQUEST["etteaste"], $_REQUEST["aeg"]);
    $kask->execute();
    header("Location: $_SERVER[PHP_SELF]");
    $yhendus->close();
    exit();
  }

?>
<!doctype html>
<html>
  <head>
    <title>Kuulutused</title>
    <style type="text/css">
       #menyykiht{
         float: left;
         padding-right: 30px;
       }
       #sisukiht{
         float:left;
       }
       #jalusekiht{
         clear: left;
       }
    </style>
  </head>
  <body>
    <div id="menyykiht">
        <h2>Kuulutused</h2>
        <ul>
          <?php
             $kask=$yhendus->prepare("SELECT id, pealkiri FROM lehed");
             $kask->bind_result($id, $pealkiri);
             $kask->execute();
             while($kask->fetch()){
               echo "<li><a href='?id=$id'>".
                          htmlspecialchars($pealkiri)."</a></li>";
             }
          ?>
		  
        </ul>
        <p><a href='peole_registreerimine.htm'>Registreeri!!!!!!
                          </a></p>
    </div>
    <div id="sisukiht">
       <?php
         if(isSet($_REQUEST["id"])){
            $kask=$yhendus->prepare("SELECT id, pealkiri, sisu FROM lehed
               WHERE id=?");
            $kask->bind_param("i", $_REQUEST["id"]); 
            $kask->bind_result($id, $pealkiri, $sisu);
            $kask->execute();
            if($kask->fetch()){
              echo "<h2>".htmlspecialchars($pealkiri)."</h2>";
			  
			  echo "</br>";
              echo htmlspecialchars($sisu);
            
            } else {
              echo "Vigased andmed.";
            }
         } 
       ?>
    </div>
    <div id="jalusekiht">
       Lehe tegi Erik
    </div>
  </body>
</html>
<?php
  $yhendus->close();
?>